<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
        content="width=device-width,initial-scale=1.0,viewport-fit=cover,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <title>尤迈桃李会</title>
    <script src="js/rem.js"></script>
    <link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.8.2/skins/default/aliplayer-min.css" />
    <link rel="stylesheet" href="css/weui.min.css">
    <link rel="stylesheet" href="css/jquery-weui.min.css">
    <link rel="stylesheet" href="css/public.css">
    <link rel="stylesheet" href="css/ot-doctor-detail.css">
    <script>(function () { var _53code = document.createElement("script"); _53code.src = "https://tb.53kf.com/code/code/96d8f960b261e49515450f8953b044bc5/1"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(_53code, s); })();</script>
</head>

<body>
    <div class="pub_bar" title="尤迈桃李会" left="back"></div>
    <!--  -->
    <div class="pub-container has-tabbar bgwhite">
        <div class="doctorInfo">
            <div class="alyVideos">
            </div>
            <div class="doctorInfo_cont plr15"></div>
        </div>
        <!-- 评论 -->
        <div class="comment_cont">
            <div class="comment_title">
                <p><span>0</span>条评论</p>
                <img class="comment_close" src="./image/bar-close.png" alt="">
            </div>
            <div class="comment_listing">
                <div class="comment_list">
                </div>
                <div class="weui-loadmore loadMore">
                    <i class="weui-loading"></i>
                    <span class="weui-loadmore__tips">正在加载</span>
                </div>
                <div class="weui-loadmore weui-loadmore_line noMore hide">
                    <span class="weui-loadmore__tips">没有更多数据了</span>
                </div>
            </div>
            <div class="mycomment">
                <div class="mycomment_cont">
                    <div class="mycomment_head"><img src="" alt=""></div>
                    <div class="mycomment_msg"><input id="mycomment_msg" type="text" placeholder="请输入评论……"></div>
                </div>
                <div class="mycomment_send">发送</div>
            </div>
        </div>
    </div>
    <!-- 公共footer -->
    <div class="pub-footer">
        <ul class="tabs">
            <li class="tab-classroom"><a href="./ot-classroom-index.html">首页</a></li>
            <li class="tab-doctor active"><a href="./ot-doctor-index.html">名医</a></li>
            <li class="tab-curriculum"><a href="./ot-curriculum-index.html">课程</a></li>
            <li class="tab-forum"><a href="./classroom-index.html">讲堂</a></li>
            <li class="tab-consultation"><a href="consultation-index.html">会诊</a></li>
            <li class="tab-user"><a href="user.html">我的</a></li>
        </ul>
    </div>
    <script src="https://g.alicdn.com/de/prismplayer/2.9.3/aliplayer-h5-min.js"></script>
    <script src="js/jquery-3.6.0.min.js"></script>
    <script src="js/jquery-weui.min.js"></script>
    <script src="js/md5.js"></script>
    <script src="js/public.js"></script>
    <script>
        let doctor = getQueryString('doctor')
        let page = 0

        getData()
        function getData() {
            gethttp('/ld/doctor', {
                data: {
                    type: 'c',
                    user: getCookie('userId'),
                    id: doctor
                },
                success: function (res) {
                    console.log(res)
                    let data = res.data.doctor

                    $('.alyVideos').html(`<img class="poster" src="${data.imageUrlUi}" alt="">`)
                    if (false) {
                        $('.alyVideos').html(`<div id="players"></div>
                                        <div class="play" data-videoId="" playdom="players" height="100%" skin="true" stopScreen="true"><img
                                                src="./image/hxl/hxl-play.png" alt=""></div>`)
                    }

                    $(".doctorInfo_cont").html(`<div class="doctorInfo_left">
                                                <div class="doctorInfo_text">
                                                    <p class="doctorInfo_p1">
                                                        <span>${data.name}</span>
                                                        <span>${data.competent.name}</span>
                                                    </p>
                                                    <div class="doctorInfo_p2 text-cut-three">${data.desciption}</div>
                                                    <div class="doctorInfo_btn">
                                                        <a href="./ot-doctor-relevant.html?doctor=${data.id}&type=0">
                                                            <div>医生相关 <img src="./image/hxl/hxl-doctor05.png" alt=""></div>
                                                        </a>
                                                        <a href="./ot-doctor-relevant.html?doctor=${data.id}&type=1">
                                                            <div class="active">开始听课 <img src="./image/hxl/hxl-doctor06.png" alt=""></div>
                                                        </a>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="doctorInfo_right">
                                                <div class="thumbs ${data.like ? 'active' : ''}">
                                                    <p>${data.likeCountUi}</p>
                                                </div>
                                                <div class="comment">
                                                    <p>${data.commentCountUi}</p>
                                                </div>
                                            </div>`)
                }
            })
        }

        // 医生点赞
        $(document).on('click', '.thumbs', function () {
            posthttp('/doctor_like', {
                hasToken: true,
                data: {
                    type: 'c',
                    user: getCookie('userId'),
                    doctor: doctor
                },
                success: function (res) {
                    getData()
                }
            })
        })


        // 医生评论点赞
        $(document).on('click', '.comment_live', function () {
            let that = $(this)
            let comment = $(this).attr('data-id')
            posthttp('/doctor_comment_like', {
                hasToken: true,
                data: {
                    type: 'c',
                    user: getCookie('userId'),
                    comment: comment,
                },
                success: function (res) {
                    let likeCount = res.data.likeCount
                    if (res.data.like) {
                        that.addClass('active')
                    } else {
                        that.removeClass('active')
                    }
                    that.html(likeCount)
                }
            })
        })

        getComment()
        function getComment(type) {
            if (type) {
                loading = false
            }
            $(".loadMore").removeClass('hide')
            gethttp('/lt/doctor_comment', {
                data: {
                    type: 'c',
                    user: getCookie('userId'),
                    doctor: doctor,
                    index: page * 10,
                    count: 10
                },
                success: function (res) {
                    let list = res.data.list
                    let arr = []
                    $(".comment_title span").html(res.data.allCount)

                    list.forEach((item, index) => {
                        let html = `<div class="comment_item">
                                        <div class="comment_head"><img src="${item.userHeadImageUrl ? item.userHeadImageUrl : avatar}" alt=""></div>
                                        <div class="comment_text">
                                            <p class="comment_name text-cut-one">${item.userName ? item.userName : '用户名称'}</p>
                                            <p class="comment_msg">${item.comment}</p>
                                        </div>
                                        <div class="comment_live ${item.like ? 'active' : ''}" data-id="${item.doctor}">${item.likeCount}</div>
                                    </div>`
                        arr.push(html)
                    });

                    page == 0 ? $('.comment_list').html(arr) : $('.comment_list').append(arr)
                    if (list.length < 10) {
                        $(".noMore").removeClass('hide')
                        loading = true;
                    } else {
                        loading = false;
                    }
                    $(".loadMore").addClass('hide')
                }
            })
        }

        // 初始化加载更多
        var loading = false
        $('.comment_listing').infinite().on("infinite", function () {
            if (loading) return;
            loading = true;
            page = Number(page) + 1
            getComment()
        });

        // 发送评论
        $(document).on('click', '.mycomment_send', function () {
            let val = $('#mycomment_msg').val()
            console.log(val)
            if (!val) {
                toast("请输入内容");
                return false
            }
            posthttp('/doctor_comment', {
                hasToken: true,
                data: {
                    user: getCookie('userId'),
                    comment: val,
                    doctor: doctor
                },
                success: function (res) {
                    if (res.code == '01') {
                        toast("评论成功");
                        $('#mycomment_msg').val('')
                        page = 0
                        loading = false
                        getComment()
                    }
                }
            })
        })
    </script>
</body>

</html>